package user;

import edu.cmu.javadb.*;
import edu.cmu.javadb.exceptions.NotFlattenableException;
import edu.cmu.javadb.exceptions.NotProjectableException;
import edu.cmu.javadb.plan.condition.Condition;
import edu.cmu.javadb.plan.condition.Path;
import static edu.cmu.javadb.plan.condition.Condition.*;

public class BFS {
	public static <T>void showAll(Iterable<T> c) {
		for (T rec : c) {
			System.out.print(rec + " ");
			System.out.println();
		}
	}

	//The problem with single instance for each VCollection:
	//you load all objects
	//then how do you do rest stuff? you may still need another VCollection
	
	public static void main(String[] args) {
		Node a = new Node("a");
		Node b = new Node("b");
		Node c = new Node("c");
		Node d = new Node("d");
		Node e = new Node("e");
		Node f = new Node("f");
		Node g = new Node("g");
		Node h = new Node("h");
		
		a.addChildren(b);
		a.addChildren(c);
		
		b.addChildren(c);
		b.addChildren(d);
		c.addChildren(d);
		c.addChildren(e);
		
		d.addChildren(f);
		d.addChildren(g);
		e.addChildren(g);
		
		f.addChildren(h);
		g.addChildren(h);
		
		Node s = a, t = h;
		
		int tmp = 0;
		QueryableSet<Node> cur = new QueryableSet<Node>();
		//QueryableSet<Node> cur = VCollection.getInstance(Node.class)
		cur.add(a);
		
		while(!cur.execute().contains(t)) {
			try {
				cur = cur.project(path("Children")).flatten();
			} catch (Exception e1) {
			}
			tmp++;
		}
		System.out.println(tmp);
	}
}
